const express = require('express');
const router = express.Router();
const dealers = [];
for(let i = 0; i < 40; i++)
    dealers.push({
        id: `${i}`,
        code: `subDealer${i}`,
        name: `name${i}`,
        dealerCode: `dealerCode${i}`,
        dealerName: `dealerName${i}`,
        shortCode: `shortCode${i}`,
        shortName: `shortName${i}`,
        countryName: '中国',
        provinceName: `湖北省${i}`,
        cityName: `cityName${i}`,
        contactName: `王五${i}`,
        contactPhone: `1531545264${i}`,
        address: `address${i}`,
        status: (i % 2 === 0 ? 1 : -1),
        rowVersion: 'A111111111',
        options: (i % 2 === 0 ? ['update', 'abandon'] : ['update'])
    });

router.get('/', (req, res) => {
    const {pageIndex, pageSize, code} = req.query;
    const result = code === null || code === undefined ? dealers : dealers.filter(item => item.code.indexOf(code) >= 0);
    res.json({
        message: '',
        payload: {
            // eslint-disable-next-line radix
            content: result.slice(parseInt(pageIndex) * parseInt(pageSize), (parseInt(pageIndex) + 1) * parseInt(pageSize)),
            totalElements: result.length,
        }
    });
});

router.get('/:id', (req, res) => {
    const {id} = req.params;
    res.json(
        {
            message: 'string',
            payload: {
                id: `${id}`,
                code: `201900${id}`,
                name: `JXSMC00${id}`,
                dealerId: `dealerId${id}`,
                dealerCode: `dealerCode${id}`,
                dealerName: `dealerName${id}`,
                shortCode: `JC00${id}`,
                shortName: `简称${id}`,
                regionId: '1',
                areaId: '1',
                areaName: '东亚',
                countryId: '1',
                countryName: '中国',
                provinceId: '1',
                provinceName: '上海',
                cityId: '1',
                cityName: '上海',
                contactName: '王五',
                contactPhone: '18454616851',
                address: '长沙11111111111111111',
                fax: 'CZ126',
                zipCode: '412000',
                email: '484868789@qq.com',
                rowVersion: '111111111111',
                buildDate: '2019-08-01',
                juridicalPerson: 'juridicalPersontest',
                juridicalPersonPhone: 'juridicalPersonPhonetest',
                juridicalPersonEmail: 'juridicalPersonEmailtest',
                generalManager: 'generalManagertest',
                generalManagerPhone: 'generalManagerPhonetest',
                generalManagerEmail: 'generalManagerEmailtest',
                salesDirector: 'salesDirectortest',
                salesDirectorPhone: 'salesDirectorPhonetest',
                salesDirectorEmail: 'salesDirectorEmailtest',
                serviceDirector: 'serviceDirectortest',
                serviceDirectorPhone: 'serviceDirectorPhonetest',
                serviceDirectorEmail: 'serviceDirectorEmailtest',
                marketDirector: 'marketDirectortest',
                marketDirectorPhone: 'marketDirectorPhonetest',
                marketDirectorEmail: 'marketDirectorEmailtest',
                financialController: 'financialControllertest',
                financialControllerPhone: 'financialControllerPhonetest',
                financialControllerEmail: 'financialControllerEmailtest',
                salesInterfacePerson: 'salesInterfacePerson',
                salesInterfacePhone: 'salesInterfacePhone',
                salesInterfaceEmail: 'salesInterfaceEmail',
                serviceInterfacePerson: 'serviceInterfacePerson',
                serviceInterfacePhone: 'serviceInterfacePhone',
                serviceInterfaceEmail: 'serviceInterfaceEmail',
                incorporatedDate: '2018-01-01',
                startTime: '2018-01-01',
                authorisedMethod: 1,
                authorisedArea: 'string',
                arrivedAddress: 'string',
                openDate: '2018-01-01',
                onlineStatus: 1,
                updatedDate: '2018-01-01',
                options: (id % 2 === 0 ? ['update', 'abandon'] : ['update'])
            }
        }
    );
});

router.put('/:id', (req, res) => {
    res.json({
        message: '编辑成功'
    });
});

router.post('/', (req, res) => {
    res.json({
        message: '新增成功'
    });
});

router.put('/:id/abandon', (req, res) => {
    res.json({
        message: '作废成功'
    });
});

router.post('/import', (req, res) => {
    res.json({
        message: '上传成功'
    });
});
module.exports = router;
